package net.malkuth.test;

import android.content.Intent;
import android.os.CountDownTimer;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.TextView;
import android.widget.Toast;

import net.malkuth.util.ActivityUtil;

/**
 * Created by 一些年华 on 2016/7/8.
 */
public class ForgetPwdActivity extends BaseNewActivity implements View.OnClickListener {
    private TextView title;
    private EditText ed_account;//账号
    private EditText ed_code;//
    private EditText ed_new_pwd;//新密码
    private Button btn_code;
    private Button btn_existence;
    private Button mRegister;
    private ImageButton mBack;


    private void initView() {

        title = (TextView) findViewById(R.id.tv_title_bar);
        title.setText(R.string.bt_forget_password);

        ed_account = (EditText) findViewById(R.id.ed_account);
        ed_code = (EditText) findViewById(R.id.ed_code);
        ed_new_pwd = (EditText) findViewById(R.id.ed_new_pwd);
        btn_code = (Button) findViewById(R.id.btn_getcode);
        btn_existence = (Button) findViewById(R.id.btn_existence);
        mRegister = (Button) findViewById(R.id.btn_register);
        mBack = (ImageButton) findViewById(R.id.iv_back);


        ed_account.setOnClickListener(this);
        ed_code.setOnClickListener(this);
        ed_new_pwd.setOnClickListener(this);
        btn_code.setOnClickListener(this);
        btn_existence.setOnClickListener(this);
        mRegister.setOnClickListener(this);
        mBack.setOnClickListener(this);

        ed_account.addTextChangedListener(textWatcher);
        ed_code.addTextChangedListener(textWatcher);
        ed_new_pwd.addTextChangedListener(textWatcher);


    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btn_complete://点击完成
                if (TextUtils.isEmpty(ed_account.getText().toString().trim())) {
                    Toast.makeText(ForgetPwdActivity.this, ActivityUtil.RstringToString(ForgetPwdActivity.this, R.string.ed_account_text), Toast.LENGTH_SHORT).show();
                } else if (TextUtils.isEmpty(ed_code.getText().toString().trim())) {
                    Toast.makeText(ForgetPwdActivity.this, ActivityUtil.RstringToString(ForgetPwdActivity.this, R.string.ed_input_code), Toast.LENGTH_SHORT).show();
                } else if (TextUtils.isEmpty(ed_new_pwd.getText().toString().trim())) {
                    Toast.makeText(ForgetPwdActivity.this, ActivityUtil.RstringToString(ForgetPwdActivity.this, R.string.ed_new_pwd), Toast.LENGTH_SHORT).show();
                } else {
                    btn_code.setBackgroundResource(R.drawable.login_button_bg);
                }
                break;

            case R.id.ed_account://请输入账号

                break;
            case R.id.btn_getcode://获取验证码


                break;
            case R.id.ed_new_pwd://请输入密码

                break;
            case R.id.btn_existence://已有账号
                finish();
                break;
            case R.id.btn_register://注册
                startActivity(new Intent(this, RegisterActivity.class));
                finish();
                break;
            case R.id.iv_back:
                this.finish();
                break;
        }
    }

    /**
     * 账号监听
     */
    TextWatcher textWatcher = new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {

        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {

        }

        @Override
        public void afterTextChanged(Editable s) {

        }
    };

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }

    /**
     * 倒计时
     */

    private CountDownTimer timer = new CountDownTimer(60 * 1000, 1000) {
        @Override
        public void onTick(long millisUntilFinished) {
            btn_code.setText("重新获取" + "（" + millisUntilFinished / 100 + "）");
        }

        @Override
        public void onFinish() {
            btn_code.setText(R.string.btn_get_code);
        }
    };

    @Override
    public void setupView() {
        initView();
    }

    @Override
    public void setContent() {
        setContentView(R.layout.activity_forgetpwd);
    }

    @Override
    public void setModel() {

    }

    @Override
    public boolean getIntentValue() {
        return true;
    }
}
